package com.example.bootredis.utils;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @Author: crush
 * @Date: 2021-08-19 16:14
 * version 1.0
 */
public class Demo1 {
    public static void main(String[] args) throws Exception {
        new Thread(new RunnableDemo1(), "AA").start();

        FutureTask<Integer> futureTask = new FutureTask<>(new CallableDemo<Integer>());
        new Thread(futureTask, "BB").start();
        // 在线程执行完后，我们可以通过futureTask的get方法来获取到返回的值。
        System.out.println(futureTask.get());
    }
}

class RunnableDemo1 implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "::通过实现Runnable来执行任务");
    }
}

class CallableDemo<Integer> implements Callable<java.lang.Integer> {

    @Override
    public java.lang.Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "::通过实现Callable接口来执行任务，并返回结果！");
        return 1024;
    }
}

